﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 第三次作业
{
    public class Node<T>
    {
        public Node<T> next { get; set; }
        public T Data { get; set; }
        public Node(T data)
        {
            this.next = null;
            Data = data;
        }
    }
    public class List<T>
    {
        private Node<T> head,tail;
        public List()
        {
            head = tail = null;
        }
        public Node<T>Head { get { return head; } }
        public void Add(T t) {
            Node<T>n=new Node<T>(t);
            if(head == null)
            {
                head = tail = n;
            }
            else
            {
                tail.next = n;
                tail = n;
            }
        }
        public void ForEach(Action<T> action)
        {
            Node<T> n = head;
            while(n != null)
            {
                action(n.Data); n = n.next;
            }
        }
    }
    internal class c4
    {
        static void Main()
        {
            List<int> list = new List<int>();
            list.Add(5);
            list.Add(2);
            list.Add(8);
            list.Add(1);
            list.Add(4);
            Console.Write("链表元素：");
            list.ForEach(x => Console.Write($"{x} "));
            Console.WriteLine();
            int max = int.MinValue;
            list.ForEach(x => { if (x > max) max = x; });
            Console.WriteLine($"最大值：{max}");
            int min = int.MaxValue;
            list.ForEach(x => { if (x < min) min = x; });
            Console.WriteLine($"最小值：{min}");
            int sum = 0;
            list.ForEach(x => sum += x);
            Console.WriteLine($"元素和：{sum}");
        }
    }

}
